<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:define name="head-title">
        <title>Create New Material Purchasing Order | Merlion's ERP System</title>
    </ui:define>

    <ui:define name="content">
        <f:view beforePhase="#{createMaterialOrder.initView}">
            <h:form>
                <p:panel id="panel" header="Add New Material Purchasing Order"> 
                    <p:ajaxStatus style="width:16px;height:16px;">   
                        <f:facet name="start">   
                            <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                        </f:facet> 

                        <f:facet name="complete">   
                            <h:outputText value="" />   
                        </f:facet>   
                    </p:ajaxStatus>

                    <p:messages id ="message"/> 

                    <p:spacer height="15"/>

                    <p:fieldset legend="Add New Material Purchasing Order">

                        <h:panelGrid columns="3" cellpadding="2" id ="panelGrid"> 

                            <h:outputLabel for="materialType" value="Material Type: " /> 
                            <h:selectOneMenu id="materialType" value="#{createMaterialOrder.selectMaterial}" >
                                <f:selectItems value="#{createMaterialOrder.materialTypes}"/>
                            </h:selectOneMenu>
                            <p:message for="materialType" />

                            <h:outputLabel for="quantity" value="Lot Quantity: " /> 
                            <p:inputText required="true" label="quantity" requiredMessage="Lot Quantity is required" id="quantity" value="#{createMaterialOrder.lotQuantity}">                         
                            </p:inputText>
                            <p:message for="quantity"/>

                            <p:commandButton id="submit" value="Submit" update="table1 quantity supplierType materialType message" actionListener="#{createMaterialOrder.displayTempList(event)}" ajax="true" />

                        </h:panelGrid>

                        <p:spacer height="20"/>

                        <p:dataTable id="table1" var="materialLine" value="#{createMaterialOrder.tempMaterialLines}"
                                     dynamic="true" emptyMessage="No Record Yet!">
                            <p:column sortBy="#{materialLine.rawMaterial.materialType}">
                                <f:facet name="header">
                                    <h:outputText value="Material Type"/>
                                </f:facet>
                                <h:outputText value="#{materialLine.rawMaterial.materialType}"/>
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Lot Quantity"/>
                                </f:facet>
                                <h:outputText value="#{materialLine.lotQuantity}"/>
                            </p:column>

                        </p:dataTable>

                        <h:outputLabel for="selectSupplier" value="Choose supplier: " /> 
                        <h:selectOneMenu id="supplierType" value="#{createMaterialOrder.selectSupplier}" >
                            <f:selectItems value="#{createMaterialOrder.suppliers}"/>
                        </h:selectOneMenu>
                        <p:spacer height="20"/>
                        <p:message for="supplierType" /> 
                        
                        <p:commandButton id="save" value="Create Material Purchasing Order" update="panel" actionListener="#{createMaterialOrder.saveMaterialOrder(event)}" ajax="true" />

                    </p:fieldset>

                </p:panel> 
            </h:form>
        </f:view>
    </ui:define>

</ui:composition>
